export default {
    data() {
        return {
            exportShow: false,
            ruless: {
                bjdm: [{
                    required: false,
                    message: '请选择班级',
                    trigger: 'change'
                }],
                xj: [{
                    required: false,
                    message: '请选择学级',
                    trigger: 'change'
                }],
                zydm: [{
                    required: false,
                    message: '请选择专业',
                    trigger: 'change'
                }],
                mb: [{
                    required: true,
                    message: '请添加导入模板',
                    trigger: 'change'
                }],
            },
            newZy: [],
            newClassList: [],
            newXjList: [],
            model: {
                zydm: '',
                bjdm: '',
                mb: '',
                xj: ''
            }
        }
    },
    created() {
        // this.getZyListNew()
    },
    methods: {
        // 
        handleResetPassword(row) {
            console.log(row);
            this.$confirm(`重置后密码改为“123456”，是否重置“${row.name}”的密码？`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let params = {
                    id: row.id
                };
                this.$ajax.post("/sysuser/resetById", params).then(res => {
                    if (res.state.code == '0') {
                        this.$message.success('重置成功！');
                    } else {
                        this.$message.error('请求失败！');
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        getZyListNew() {
            let params = {
                schoolid: this.schoolid
            };
            this.$api.jyz.getZyList(params).then(res => {
                if (res.code == '0') {
                    this.newZy = res.list;
                    if (res.list.length != 0) {
                        this.model.zydm = res.list[0].zydm
                        this.upData.zydm = res.list[0].zydm
                        this.getNewClassData()
                    } else {
                        this.model.zydm = ""
                    }
                } else {
                    this.$message.error('请求失败！');
                }
            })
        },
        getNewClassData(e) {
            this.upData.zydm = this.model.zydm
            this.$ajax.post('/dclass/classList', {
                schoolid: this.schoolid,
                zydm: this.model.zydm,
                // xj:this.model.xj
            }).then(res => {
                console.log(res);
                if (res.code == 0) {
                    //this.newClassList
                    const newArr = []
                    res.list.forEach(
                        item => {
                            const itemnew = item
                            if (!newArr.some(o => o.xj == item.xj)) {
                                newArr.push(item)
                            }
                        }
                    )
                    this.newClassList = newArr
                    this.model.xj = ""
                    this.model.bjdm = ""

                }
            })
        },
        changeClass(e) {
            console.log('changeClass=>', e,'==========');
            this.upData.bjdm = this.model.bjdm

        },
        changeClass2(e) {
            console.log('changeClass=>', e);
            this.model.xj = e
            this.$ajax.post('/dclass/classList', {
                schoolid: this.schoolid,
                zydm: this.model.zydm,
                xj: this.model.xj
            }).then(res => {
                console.log(res);
                if (res.code == 0) {
                    this.newBxList = res.list
                    // this.model.xj = ""
                    // this.model.bjdm = ""

                }
            })

        },
        exportStudent() {
            this.$refs['model'].validate((valid) => {
                if (valid) {
                    this.$refs.upload.submit()
                } else {
                    return false;
                }
            });
        }
    }
}
